import '../../../app_files.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:fish_redux/fish_redux.dart';
import 'dart:core';
import '../webview_flutter_component/state.dart';

class WebViewState implements GlobalBaseState<WebViewState> {
  String url;
  String title;

  WebViewController webViewController;
  bool isLoad = false;
  bool requestRefresh = false;
  WebViewConfigModel webInfo;

  @override
  UserInfoEntity userInfo;

  @override
  WebViewState clone() {
    return WebViewState()
      ..userInfo = userInfo
      ..webViewController = webViewController
      ..url = url
      ..title = title
      ..isLoad = isLoad
      ..requestRefresh = requestRefresh
      ..webInfo = webInfo;
  }
}

WebViewState initState(Map<String, dynamic> args) {
  WebViewState state = WebViewState()
    ..url = args['url']
    ..title = args['title']
    ..webInfo = args['webInfo'];
  return state;
}

class WebViewComponentCon extends ConnOp<WebViewState, WebViewComponentState> {
  @override
  WebViewComponentState get(WebViewState state) {
    final WebViewComponentState reportState = WebViewComponentState();
    reportState.url = state.url;
    reportState.webViewController = state.webViewController;
    if (state.requestRefresh) {
      if (state.isLoad)
        reportState.requestLoad = true;
      else {
        reportState.requestLoad = true;
      }
    }
    return reportState;
  }

  @override
  void set(WebViewState state, WebViewComponentState substate) {
    state.webViewController = substate.webViewController;
    state.isLoad = substate.isLoad;
    state.requestRefresh = substate.reRresh;
  }
}
